/*
 * @Author: szx
 * @Date: 2022-03-31 13:04:23
 * @LastEditTime: 2022-03-31 13:10:16
 * @Description:
 * @FilePath: \leetcode\700-799\713\713.js
 */
/**
 * @param {number[]} nums
 * @param {number} k
 * @return {number}
 */
var numSubarrayProductLessThanK = function (nums, k) {
    let res = 0;
    let l = 0;
    let sum = 1;
    for (let r = 0; r < nums.length; r++) {
        sum *= nums[r];
        while (sum >= k && l <= r) {
            sum = Math.floor(sum / nums[l]);
            l++;
        }
        res += r - l + 1;
    }
    return res;
};
console.log(numSubarrayProductLessThanK([10, 5, 2, 6], 100));
console.log(numSubarrayProductLessThanK([1, 2, 3], 0));
